package com.litchi.activity;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;

import com.litchi.R;
import com.litchi.app.MyApplication;
import com.litchi.bean.BrandStory;
import com.litchi.utils.Constants;

public class BrandStoryActivity extends Activity implements OnClickListener {

	private ImageView img1, img2;
	private TextView text1, text2;
	private MyApplication mApplication;
	private int textLine1 = 3, textLine2 = 3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_brand_story);
		mApplication = (MyApplication) getApplicationContext();

		findViewById(R.id.img_back).setOnClickListener(this);
		text1 = (TextView) findViewById(R.id.text_wanshili);
		text1.setOnClickListener(this);
		text2 = (TextView) findViewById(R.id.text_yanxia);
		text2.setOnClickListener(this);
		img1 = (ImageView) findViewById(R.id.img_wanshili_brand);
		img2 = (ImageView) findViewById(R.id.img_yanxia_brand);
		initData();
	}

	public void initData() {
		BmobQuery<BrandStory> query = new BmobQuery<BrandStory>();
		query.findObjects(this, new FindListener<BrandStory>() {

			@Override
			public void onError(int arg0, String arg1) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onSuccess(List<BrandStory> arg0) {
				// TODO Auto-generated method stub
				text1.setText(arg0.get(0).getBrandText());
				text2.setText(arg0.get(1).getBrandText());
				mApplication.imgLoader.displayImage(Constants.HTTP_FILE
						+ arg0.get(0).getBrandImg().getUrl(), img1);
				mApplication.imgLoader.displayImage(Constants.HTTP_FILE
						+ arg0.get(1).getBrandImg().getUrl(), img2);

			}

		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_back:
			finish();
			break;
		case R.id.text_wanshili:
			if (textLine1 == 3) {
				textLine1 = 100;

			} else {
				textLine1 = 3;

			}
			text1.setMaxLines(textLine1);
			break;
		case R.id.text_yanxia:
			if (textLine2 == 3) {
				textLine2 = 100;

			} else {
				textLine2 = 3;

			}
			text2.setMaxLines(textLine2);
			break;
		default:
			break;
		}
	}

}
